package CreatePhase;


import Entities.Scene;
import Phase.JDoubleBufferedPanel;
import Visitor.IVisitor;
import Visitor.PaintVisitor;
import java.util.logging.Level;
import java.util.logging.Logger;

public class CreatePhaseRenderer extends Thread{

    private JDoubleBufferedPanel canvas;
    private Scene scene;
    private boolean stop = false;
    
    public CreatePhaseRenderer(JDoubleBufferedPanel canvas, Scene scene) {
        this.canvas = canvas;
        this.scene = scene;
    }
    
    @Override
    public void run(){
        while(!stop){
            try {
                canvas.getImage().getGraphics().clearRect(0, 0, 300, 300);
                IVisitor paintVisitor = new PaintVisitor(canvas.getImage().getGraphics());
                scene.accept(paintVisitor);
                
                canvas.repaint();
                Thread.sleep(5);
            } catch (InterruptedException ex) {
                Logger.getLogger(CreatePhaseRenderer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public void setStop(boolean stop) {
        this.stop = stop;
    }
    
}
